<!DOCTYPE html>
<html lang="zh-cmn-Hans">

<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="IE=edge, chrome=1">
    <title>debounce</title>
    <style>
        #container {
            width: 100%;
            height: 200px;
            line-height: 200px;
            text-align: center;
            color: #fff;
            background-color: #444;
            font-size: 30px;
        }
    </style>
</head>

<body>
    <div id="container"></div>
</body>

<script>
    // 第一版
    var count = 1;
    var container = document.getElementById('container');

    function getUserAction() {
        container.innerHTML = count++;
    };

    container.onmousemove = debounce(getUserAction, 1000);

    function debounce(func, wait) {
        var timeout;
        return function() {
            debugger
            clearTimeout(timeout)
            timeout = setTimeout(func, wait);
        }
    }

    function debounce1() {
        return function() {
            timeout1 = setTimeout(console.log(222), 1000);
        }
    }

    debounce1();
</script>

</html>

</html>